package com.jt.www.enums.extend;

import com.jt.www.model.remote.ins.EduExtendVO;
import com.jt.www.model.reps.GenericListResponse;
import com.jt.www.remote.ins.InsClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.ResponseEntity;

/**
 * 扩展信息查询方法枚举
 */

public enum ExtendMothedEnum {

    APP_FORM_EXTENDS("selectAppFormExtends", true, false, "查询投保单扩展信息") {
        @Override
        public ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param) {
            try {
                return insClient.selectAppFormExtends(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    },
    INS_OBJECT_EXTENDS("selectInsObjectExtends", true, false, "查询被保人的扩展信息") {
        @Override
        public ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param) {
            try {
                return insClient.selectInsObjectExtends(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    },
    HUMAN_EXTENDS("selectHumanExtends", true, false, "查询被保险人(个人)扩展信息") {
        @Override
        public ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param) {
            try {
                return insClient.selectHumanExtends(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    },
    CORPORATION_EXTENDS("selectCorporationExtends", true, false, "查询被保险人(企业)扩展信息") {
        @Override
        public ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param) {
            try {
                return insClient.selectCorporationExtends(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    },
    POLICY_BIZ_RES("selectBizResByPolicyIds", false, true, "通过保单ID查询资源绑定表") {
        @Override
        public ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param) {
            try {
                return insClient.selectBizResByPolicyIds(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    },
    APP_BIZ_RES("selectBizResByAppIds", true, false, "通过投保单ID查询资源绑定表") {
        @Override
        public ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param) {
            try {
                return insClient.selectBizResByAppIds(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    };

    /**
     * 请求方法名称
     */
    private String mothedName;
    /**
     * 使用appId查询
     */
    private boolean isAppId;
    /**
     * 使用policyId查询
     */
    private boolean isPolicyId;

    /**
     * 描述
     */
    private String desc;


    ExtendMothedEnum(String mothedName, boolean isAppId, boolean isPolicyId, String desc) {
        this.mothedName = mothedName;
        this.isAppId = isAppId;
        this.isPolicyId = isPolicyId;
        this.desc = desc;
    }

    /**
     * 通过code及渠道类型查询枚举值
     *
     * @param mothedName
     * @return
     */
    public static ExtendMothedEnum getExtendMothedEnum(String mothedName) {

        if (StringUtils.isBlank(mothedName)) {
            return null;
        }
        for (ExtendMothedEnum mothedEnum : ExtendMothedEnum.values()) {
            //如果不传默认为查询所有的
            if (mothedEnum.mothedName.equals(mothedName)) {
                return mothedEnum;
            }
        }
        return null;
    }

    /**
     * 查询扩展字段名
     *
     * @param insClient 远程调用
     */
    public abstract ResponseEntity<GenericListResponse<EduExtendVO>> select(InsClient insClient, String param);

    public String getMothedName() {
        return mothedName;
    }

    public void setMothedName(String mothedName) {
        this.mothedName = mothedName;
    }

    public boolean isAppId() {
        return isAppId;
    }

    public void setAppId(boolean appId) {
        isAppId = appId;
    }

    public boolean isPolicyId() {
        return isPolicyId;
    }

    public void setPolicyId(boolean policyId) {
        isPolicyId = policyId;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
